/**    
* @Title: ConfEnvironmentPostProcessor.java  
* @Package com.kaver.conf.springboot.autoConfiguration   
* @author roc   
* @date 2019年2月13日 下午5:25:06  
* @version V1.0  
* @copyright kaver 
*/
package com.kaver.conf.springboot.autoConfiguration;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;

import com.kaver.constant.PropertyConstant;
import com.kaver.spring.AppInstance;

/**
 * @ClassName: ConfEnvironmentPostProcessor
 * @Description: springboot 自定义配置
 * @author roc
 * @date 2019年2月13日 下午5:25:06
 * 
 */
public class ConfEnvironmentPostProcessor implements EnvironmentPostProcessor {

	@Override
	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
		String environmentName = environment.getClass().getName();
		if ("org.springframework.web.context.support.StandardServletEnvironment".equals(environmentName)
				|| "org.springframework.boot.web.reactive.context.StandardReactiveWebEnvironment"
						.equals(environmentName)) {
			String confEnable = environment.getProperty(PropertyConstant.CONF_ENABLE);
			if (confEnable == null || (confEnable!= null && !"false".equals(confEnable))) {
				AppInstance.initAppInstance(environment);
				AppInstance.loadLocalAndRomoteProperties();
				AppInstance.merge(environment);
			}
		}
	}

}
